package com.example.demo.service.impl;

import com.example.demo.entity.ArticleRemarks;
import com.example.demo.entity.DTO.ArticleRemarksDTO;
import com.example.demo.entity.VO.ArticleRemarksVO;
import com.example.demo.mapper.ArticleRemarksMapper;
import com.example.demo.service.IArticleRemarksService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.we
 * @since 2024-06-04
 */
@Service
public class ArticleRemarksServiceImpl extends ServiceImpl<ArticleRemarksMapper, ArticleRemarks> implements IArticleRemarksService {

    @Autowired
    private ArticleRemarksMapper articleRemarksMapper;
    @Override
    public int addRemarks(ArticleRemarks articleRemarks) {
        if (articleRemarks.getUserId() < 0) {
            // 这里我选择了返回一个错误码 -1
            return -1;
        }
        return articleRemarksMapper.addRemarks(articleRemarks);
    }

    @Override
    public List<ArticleRemarksDTO> selectAllRemarks() {
        return articleRemarksMapper.selectAllRemarks();
    }

    @Override
    public int updateRemarks(ArticleRemarks articleRemarks) {
        List<ArticleRemarks>  articleRemarks1 = articleRemarksMapper.selectRemarksByThreeId(articleRemarks);
        if(articleRemarks1 != null){
            articleRemarksMapper.updateRemarks(articleRemarks);
        }
        return 0;
    }

    @Override
    public int deleteRemarks(ArticleRemarks articleRemarks) {
        List<ArticleRemarks>  articleRemarks1 = articleRemarksMapper.selectRemarksByThreeId(articleRemarks);
        if(articleRemarks1 != null){
            articleRemarksMapper.deleteRemarks(articleRemarks);
        }
        return 0;
    }

    @Override
    public List<ArticleRemarksDTO> findAllByUserId(int userId) {
        return articleRemarksMapper.selectRemarksByUserId(userId);
    }
}
